package com.example.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * ,@Repository用于标注数据访问组件,即DAO组件
 */
@Repository
public class RedisDao {
    @Autowired
    private StringRedisTemplate template;

    public void setKey(String key,String value){
        ValueOperations<String,String> operations = template.opsForValue();
        operations.set(key,value,1, TimeUnit.MINUTES);//一分钟过期
    }
    public String getValue(String key){
        ValueOperations<String,String> operations = template.opsForValue();
        return operations.get(key);
    }
}
